home *** CD-ROM | disk | FTP | other *** search
- Path: news.ov.com!news
- From: glenn@ov.com (Fletcher.Glenn@ov.com)
- Newsgroups: comp.lang.c
- Subject: Re: Help with simple code
- Date: 17 Jan 1996 19:27:46 GMT
- Organization: OpenVision
- Message-ID: <4djiji$70n@spanky.pls.ov.com>
- References: <4dbak5$oij@ionews.io.org>
- Reply-To: glenn@ov.com
- NNTP-Posting-Host: foghorn.pls.ov.com
-
- In article oij@ionews.io.org, jgordon@io.org (John Gordon MacPherson) writes:
- >Can anyone tell me what's wrong with this piece of code? I lifted it
- >straight from a textbook.
- >
- >Here's the code:
- >
- >/* Calculating compound interest */
- >#include <stdio.h>
- >#include <math.h>
- >
- >main()
- >{
- > int year;
- > double amount, principal = 1000, rate = 0.5;
- >
- > printf("%4s%21s\n", "Year", "Amount on deposit");
- >
- > for (year = 1; year <= 10; year++) {
- > amount = principal * pow(1.0 + rate, year);
- > printf("%4d%21.2f\n", year, amount);
- > }
- >
- > return 0;
- >}
- >______________________________________________________________
- >
- >and here's the error:
- >
- >In function `main':
- >undefined reference to `pow'
- >
- >I don't understand. `pow' is a function, not a variable?
- >Can anyone tell me what's wrong?
- >
- >
-
-
- You need to add "-lm" to the end of your compile line. This command will
- include the math library that defines the pow() function.
-
- Fletcher.Glenn@ov.com
-
-
-